/* Eshm - SHM abstraction
 * Copyright (C) 2008-2012 Jorge Luis Zapata
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "Eshm.h"
#include "eshm_private.h"

/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
static int _init = 0;
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
int eshm_log_dom = -1;
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/
int ESHM_ERROR_ACCESS;
int ESHM_ERROR_EXIST;
int ESHM_ERROR_NEXIST;
int ESHM_ERROR_CODEC;
int ESHM_ERROR_TIMEOUT;
/**
 * Initialize the library
 * @return The number of times the library has been initialized
 */
EAPI int eshm_init(void)
{
	if (!_init)
	{
		eina_init();
		/* register the domain */
		eshm_log_dom = eina_log_domain_register("eshm", NULL);
		/* register the errors */
		ESHM_ERROR_ACCESS = eina_error_msg_register("Not enough permission for the request");
		ESHM_ERROR_EXIST = eina_error_msg_register("Segment already exists");
		ESHM_ERROR_NEXIST = eina_error_msg_register("Segment does not exist");
		ESHM_ERROR_CODEC = eina_error_msg_register("Encoding / Decoding failed");
		ESHM_ERROR_TIMEOUT = eina_error_msg_register("Timeout waiting for response");
	}
	return ++_init;
}
/**
 * Shutdowns the library
 */
EAPI void eshm_shutdown(void)
{
	if (!--_init)
	{
		/* unregister the log */
		eina_log_domain_unregister(eshm_log_dom);
		/* unregister the errors */
		eina_shutdown();
	}
}
